﻿using CommunityToolkit.Mvvm.Input;
using Macad.Core;
using Macad.Core.Topology;
using Macad.Interaction;
using Macad.Occt;
using SpCad;
using SPCAM.Plugin.Cam.Model;
using SPCAM.Plugin.Cam.Servers;
using SPCAM.Plugin.Cam.Tools;
using SPCAM.Plugin.Cam.Views;
using static SPCAM.Plugin.Cam.Tools.MoveToZero;

namespace SPCAM.Plugin.Cam.ViewModel
{
    public partial class Commands:CamViewModelBase
    {

        #region Command

        [RelayCommand]
        private void QuitTool()
        {
             
            ClearSelect();
        }
       
        [RelayCommand]
        private void Import()
        {
           
            Sv.spView.Import();
        }
        [RelayCommand]
        private void SelectEdge()
        {
      
            try
            {
            
                SelectShapeModel model=new SelectShapeModel();
                model.item= new UView_SelectEdge();
                model.tool = new SelectEdgeTools(SpServer.Instance.SelectBody);
                SelectShape(model);

                DoTools();
              

            }
            catch (Exception)
            {
                SpServer.Instance.SetHintMessage("出现错误~_~,请先选择实体");
                ClearSelect();
            }
        }
        #region 选择面功能能
        [RelayCommand]
        private void SelectFace()
        {
            try
            {
                if (SpServer.Instance.SelectBody == null) {
                    SpServer.Instance.SetHintMessage("出现错误~_~,请先选择实体");
                    ClearSelect();
                    return;
                }
                SelectShapeModel model = new SelectShapeModel
                {
                    item = new UView_SelectFace(),
                    tool = new SelectFasceTools(SpServer.Instance.SelectBody)
                };
                SelectShape(model);
                DoTools();
              

            }
            catch (Exception)
            {
                SpServer.Instance.SetHintMessage("出现错误~_~,请先选择实体");
                ClearSelect();
            }
        }
        #endregion
        [RelayCommand]
        private void DoFaceWeld()
        {

            SpServer.Instance.RemoveHintMessage();
            if (InteractiveContext.Current?.WorkspaceController.CurrentTool is SelectFasceTools)
            {
                SelectFasceTools? facetools = (SelectFasceTools)InteractiveContext.Current?.WorkspaceController.CurrentTool!;
                if (facetools != null)
                {
                    if (facetools._SelectFaces.Count > 0)
                    {
                        var cd = facetools.FaceActionEdge(SelctFaceType);
                      

                    }
                }
            }



        }
    

        #endregion
        [RelayCommand]
        private void DoSelectTools()
        {
         
           // DoTools();
        }
        [RelayCommand]
        private void DoMoveZore(string pr)
        {
            MoveTope _MoveTope= MoveTope.mini;
            switch (pr)
            {
                case "max":
                    _MoveTope = MoveTope.max;
                    break;
                case "mini":
                    _MoveTope = MoveTope.mini;
                    break;
                case "set":
                    _MoveTope = MoveTope.setpont;
                    break;
                case "zore":
                    _MoveTope=MoveTope.Zore;
                    break;
                default:
                    break;
            }
            if (SpServer.Instance.SelectBody == null)
            {
                SpServer.Instance.SetHintMessage("必须选择一个实体");
                return;
            }
            MoveToZero mtz = new MoveToZero(SpServer.Instance.SelectBody, _MoveTope);
            SpServer.Instance.StartTools(mtz);
        }
    }
}
